<?php
// +---------------------------------------------------------------------------+
// | This file is part of the KnowledgebasePublisher package                   |
// | KnowledgebasePublisher - web based knowledgebase publisher tool           |
// |                                                                           |
// | Author:  Evgeny Leontev <eleontev@gmail.com>                              |
// | Copyright (c) 2005 Evgeny Leontev                                         |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

class KBComment extends AppObj
{


	var $properties = array('id'		 	=> NULL,
							'user_id'		=> '',
							'entry_id' 		=> '',
							'name'	 		=> '',
							'email' 		=> '',
							'comment' 		=> '',
							'date_posted'	=> '',
							'active'		=> 1
							);
	
	var $hidden = array('id','user_id','entry_id','date_posted');
	var $title;
	var $username;
	var $r_email;
	
	
	function _callBack($property, $val) {
		if($property == 'date_posted' && !$val) {
			$val = date('Y-m-d');
		}
		
		return $val;
	}
	
	
	// so we extend base set function
	function set($key_or_arr, $value = false) {
		parent::set($key_or_arr, $value);
		
		$this->title = $key_or_arr['title'];
		$this->username = $key_or_arr['username'];
		$this->r_email = $key_or_arr['r_email'];
	}
	
	
	function validate($values) {
		
		require_once 'eleontev/Validator.php';
		
		$required = array('comment');
		
		$v =& new Validator($values, false);

		// check for required first, return errors
		$v->requiredArray('required_msg', $required);
		if($v->getErrors()) {
			$this->errors =& $v->getErrors();
			return true;
		}
		
		$v->regex('email_msg', 'email', 'email', false);
		if($v->getErrors()) {
			$this->errors =& $v->getErrors();
			return true;
		}
	}
	
}
?>